package com.jiaai.shop.store.mapper;

import com.baomidou.mybatisplus.mapper.Wrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.jiaai.shop.store.entity.SMember;
import com.baomidou.mybatisplus.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;
import java.util.Map;

/**
 * <p>
  * 会员表 Mapper 接口
 * </p>
 *
 * @author
 * @since 2018-04-01
 */
@Mapper
public interface SMemberMapper extends BaseMapper<SMember> {

    /**
     * 购买商品后更新每天返还积分
     * */
    @Update("UPDATE s_member \n" +
            "SET returnIntegral = returnIntegral+#{integral},\n" +
            "lv=#{lv},state=1 \n" +
            "WHERE memberId=#{member}")
    boolean updateeturnIntegral(@Param("integral") int Integral,@Param("lv")int lv,@Param("member") String member);
    /**
     * 更新已经有的总积分数量
     * */
    @Update("UPDATE s_member \n" +
            "SET total_score=total_score+#{inter} \n" +
            "WHERE memberId=#{mId}")
    boolean updateTotalScore(@Param("inter") int inter,@Param("mId") String mId);
    /**
     * 搜索出所有充值过的的会员
     * */
    @Select("SELECT t2.member \n" +
            "FROM s_member t2 \n" +
            "WHERE t2.state=1")
    List<Map> seachAllMember();
    /**
     * 搜索会员的返利积分
     */
    @Select("SELECT t1.returnIntegral \n" +
            "FROM s_member t1 \n" +
            "WHERE t1.memberId=#{mId}")
    int seachInter(@Param("mId") String mId);

    /**
     * 搜索所有注册会员，降序排列
     * */
    @Select("SELECT * \n" +
            "FROM s_member \n" +
            "${ew.sqlSegment} ORDER BY time DESC")
    List<Map<String,Object>> seachMember(Page page,@Param("ew") Wrapper wrapper);

    /**
     * 同意提现后，用户积分扣除
     * */
    @Update("UPDATE s_member \n" +
            "SET total_score=total_score-20 \n" +
            "WHERE memberId=#{mId}")
    boolean updateMidScore(@Param("mId") String mId);

    /**
     * 根据用户名查询密码
     * */
    @Select("SELECT memberPass \n" +
            "FROM s_member \n" +
            "WHERE memberId=#{mId}")
    String seachPwd(@Param("mId") String mId);

    /**
     * 根据用户id查询用户名
     * */
    @Select("SELECT memberName \n" +
            "FROM s_member \n" +
            "WHERE memberId=#{mId}")
    String seachMemberName(@Param("mId") String mId);

    /**
     * 同意提现后，用户积分扣除
     * */
    @Update("UPDATE s_member \n" +
            "SET presentScore=#{presentScore} \n" +
            "WHERE memberId=#{mId}")
    boolean updatePresentScore(@Param("mId") String mId,Integer presentScore);

    /**
     * 根据用户名查询用户所有信息
     * */
    @Select("SELECT * \n" +
            "FROM s_member \n" +
            "WHERE memberId=#{mId}")
    String seachAllById(@Param("mId") String mId);

    /**
     * 会员忘记密码（修改密码）
     * */
    @Update("UPDATE s_member \n" +
            "SET memberPass=#{memberPass} \n" +
            "WHERE memberName=#{memberName}")
    boolean updateMemberPass(@Param("memberName") String memberName,@Param("memberPass")String memberPass);
}